The agilepy AGAnalysis class can be used not only for Maximum Likelihood analysis, but also for an Aperture Photometry analysis.
The Aperture Photometry provides the exposure and counts of an ON region.
# Import the relevant classes
from agilepy.api.AGAnalysis import AGAnalysis
from agilepy.utils.AstroUtils import AstroUtils
from astropy.coordinates import SkyCoord
from astropy.table import Table
from astropy.time import Time
This tutorial uses the available test dataset on blazar 3C 454.3, from 2010-11-13 to 2010-11-21 (MJD 55513-55521).
# Prepare the YAML Configuration File.
# You can create it manually or use AGVisibility.getConfiguration()
outputDir = "/home/flareadvocate/workspace/shared_dir/"
confFilePath = "/home/flareadvocate/workspace/shared_dir/tutorial_ap.yaml"
AGAnalysis.getConfiguration(
confFilePath = confFilePath,
# Output
outputDir = outputDir,
userName = "my_name",
sourceName = "3C454_3",
verboselvl = 0,
# Input
evtfile="$AGILE/agilepy-test-data/test_dataset_agn/EVT/EVT.index",
logfile="$AGILE/agilepy-test-data/test_dataset_agn/LOG/LOG.index",
userestapi=False,
# Selection
tmin = 55513.0,
tmax = 55521.0,
timetype = "MJD",
glon = 86.11,
glat = -38.18,
)
# Create the AGAnalysis object
ag = AGAnalysis(confFilePath)
# Update General Options
ag.setOptions(binsize=0.5, expstep=2, mapsize=25)
ag.setOptions(energybins=[[100, 50000]])
# Update Aperture Photometry Options: Radius, Timeslot
ag.setOptions(radius=2) # ON region radius
ag.setOptions(timeslot=10800) # Bin size for the Light Curve
# Check Aperture Photometry configuration
ag.printOptions("ap")
Log level set to WARNING and output to /home/flareadvocate/workspace/shared_dir/my_name_3C454_3_20251013-142701/logs
{'radius': 2, 'timeslot': 10800}
# Check General configuration
ag.printOptions()
{ 'ap': {'radius': 2, 'timeslot': 10800},
'input': { 'datapath': 'None',
'evtfile': '/home/flareadvocate/agiletools/agilepy-test-data/test_dataset_agn/EVT/EVT.index',
'logfile': '/home/flareadvocate/agiletools/agilepy-test-data/test_dataset_agn/LOG/LOG.index',
'userestapi': False},
'maps': { 'binsize': 0.5,
'energybins': [[100, 50000]],
'expstep': 2,
'fovbinnumber': 1,
'mapsize': 25,
'offaxisangle': 30,
'proj': 'ARC',
'projtype': 'WCS',
'spectralindex': 2.1,
'timestep': 160,
'useEDPmatrixforEXP': False},
'mle': { 'contourpoints': 40,
'edpcorrection': 1,
'expratio_maxthr': 15,
'expratio_minthr': 0,
'expratio_size': 10,
'expratioevaluation': True,
'fluxcorrection': 0,
'integratortype': 1,
'loccl': 5.99147,
'mindefaulttolerance': 0.01,
'minimizeralg': 'Migrad',
'minimizerdefstrategy': 2,
'minimizertype': 'Minuit',
'ranal': 10,
'ulcl': 2},
'model': { 'galcoeff': [-1],
'galmode': 1,
'galmode2': 0,
'galmode2fit': 0,
'isocoeff': [-1],
'isomode': 1,
'isomode2': 0,
'isomode2fit': 0,
'modelfile': None},
'output': { 'filenameprefix': 'analysis_product',
'outdir': PosixPath('/home/flareadvocate/workspace/shared_dir/my_name_3C454_3_20251013-142701'),
'sourcename': '3C454_3',
'username': 'my_name',
'verboselvl': 0},
'plotting': {'twocolumns': False},
'selection': { 'albedorad': 80,
'bpointing': None,
'dq': 0,
'filtercode': 5,
'fovradmax': 60,
'fovradmin': 0,
'glat': -38.18,
'glon': 86.110001,
'irf': 'H0025',
'lonpole': 180,
'lpointing': None,
'maplistgen': 'None',
'phasecode': 6,
'proj': 'ARC',
'timelist': 'None',
'timetype': 'TT',
'tmax': 217382400.0,
'tmin': 216691200.0}}
The function AGAnalysis.aperturePhotometry() calls the AGILE Tool which compute the Aperture Photometry light curve.
The output file is a text file (columns separated by whitespaces) providing four columns:
The AperturePhotometry Table can be retrieved as an astropy.table.Table object using AGAnalysis.lightCurveTable.
# Run Aperture Photometry Tool
lightCurveData, _ = ag.aperturePhotometry()
# Output file
print(lightCurveData)
/home/flareadvocate/workspace/shared_dir/my_name_3C454_3_20251013-142701/ap/analysis_product
# The output table is stored in:
ap_table = ag.lightCurveTable['ap']
display(ap_table)
| tmin_TT | tmax_TT | exposure | counts |
|---|---|---|---|
| float64 | float64 | float64 | int64 |
| 216691200.0 | 216702000.0 | 337800.79 | 0 |
| 216702000.0 | 216712800.0 | 361067.9 | 0 |
| 216712800.0 | 216723600.0 | 564908.66 | 2 |
| 216723600.0 | 216734400.0 | 524760.4 | 1 |
| 216734400.0 | 216745200.0 | 532771.08 | 1 |
| 216745200.0 | 216756000.0 | 434508.26 | 2 |
| 216756000.0 | 216766800.0 | 370341.09 | 1 |
| 216766800.0 | 216777600.0 | 443719.82 | 1 |
| 216777600.0 | 216788400.0 | 381544.55 | 1 |
| 216788400.0 | 216799200.0 | 395535.56 | 2 |
| ... | ... | ... | ... |
| 217274400.0 | 217285200.0 | 432209.84 | 12 |
| 217285200.0 | 217296000.0 | 334224.32 | 5 |
| 217296000.0 | 217306800.0 | 352824.57 | 13 |
| 217306800.0 | 217317600.0 | 261572.17 | 7 |
| 217317600.0 | 217328400.0 | 592315.71 | 11 |
| 217328400.0 | 217339200.0 | 644026.98 | 19 |
| 217339200.0 | 217350000.0 | 553286.41 | 7 |
| 217350000.0 | 217360800.0 | 447504.02 | 7 |
| 217360800.0 | 217371600.0 | 369263.81 | 7 |
| 217371600.0 | 217382400.0 | 393622.24 | 8 |
# The AstroUtils class offers a function to convert AGILE seconds to other formats:
time_min = AstroUtils.convert_time_from_agile_seconds(ap_table['tmin_TT'])
# Print e.g in MJD
display(time_min.mjd)
array([55513. , 55513.125, 55513.25 , 55513.375, 55513.5 , 55513.625,
55513.75 , 55513.875, 55514. , 55514.125, 55514.25 , 55514.375,
55514.5 , 55514.625, 55514.75 , 55514.875, 55515. , 55515.125,
55515.25 , 55515.375, 55515.5 , 55515.625, 55515.75 , 55515.875,
55516. , 55516.125, 55516.25 , 55516.375, 55516.5 , 55516.625,
55516.75 , 55516.875, 55517. , 55517.125, 55517.25 , 55517.375,
55517.5 , 55517.625, 55517.75 , 55517.875, 55518. , 55518.125,
55518.25 , 55518.375, 55518.5 , 55518.625, 55518.75 , 55518.875,
55519. , 55519.125, 55519.25 , 55519.375, 55519.5 , 55519.625,
55519.75 , 55519.875, 55520. , 55520.125, 55520.25 , 55520.375,
55520.5 , 55520.625, 55520.75 , 55520.875])
# Plot Light Curve
ag.displayLightCurve("ap", saveImage=False)
# Save Light Curve Plot
lc_plot = ag.displayLightCurve("ap", saveImage=True)
print(f"Plot saved in: {lc_plot}")
Plot saved in: /home/flareadvocate/workspace/shared_dir/my_name_3C454_3_20251013-142701/plots/light_curve_216702000.0_217382400.0.png